<%@ page language="java" contentType="text/html; charset=UTF-8"
         import="java.util.*" pageEncoding="UTF-8" %>
<%@page language="java" import="db_tool.DBConnection" %>
<%@page language="java" import="java.sql.ResultSet" %>
<%@page language="java" import="java.sql.Statement" %>

<%@page language="java" import="com.opensymphony.xwork2.ActionContext" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="edge"/>
    <meta name="author" content="Daliu"/>
    <meta name="keywords" content="长江上游珍稀特有鱼类保护信息管理系统、长江上游、珍稀特有鱼类、保护信息"/>
    <meta name="describe" content="长江上游珍稀特有鱼类保护信息管理系统"/>
    <title>长江上游珍稀特有鱼类保护信息管理系统</title>
    <link rel="icon" href="<%=path%>/bfish.ico"
          mce_href="<%=path%>/bfish.ico" type="image/x-icon">
    <link rel="shortcut icon" href="<%=path%>/bfish.ico"
          mce_href="<%=path%>/bfish.ico" type="image/x-icon">
    <%--<link href="css/register.css" rel="stylesheet"/>--%>
    <link type="text/css" href="css/partI.css" rel="stylesheet"/>
    <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
    <!-- 表单验证 -->
    <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
    <script type="text/javascript" src="js/jquery.validate.min.js"></script>

</head>
<%--<body class="background">--%>

<script type="text/javascript">
    var code; //在全局定义验证码
    //产生验证码
    window.onload = function () {
        createCode();
    }

    function createCode() {
        code = "";
        var codeLength = 4;//验证码的长度
        var checkCode = document.getElementById("codeVal");
        var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C',
            'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');//随机数
        for (var i = 0; i < codeLength; i++) {//循环操作
            var index = Math.floor(Math.random() * 36);//取得随机数的索引（0~35）
            code += random[index];//根据索引取得随机数加到code上
        }
        checkCode.value = code;//把code值赋给验证码

    }
</script>

<body>
<div class="content">
    <div class="web-width">
        <div class="for-process">
            <div class="plist for-cur"></div>
            <div class="plist"></div>
            <div class="plist"></div>
            <div class="plist"></div>
            <div class="ptextbox">
                <div class="ptext for-cur"><em>1</em><br/><strong>填写账户名</strong></div>
                <div class="ptext"><em>2</em><br/><strong>验证身份</strong></div>
                <div class="ptext"><em>3</em><br/><strong>设置新密码</strong></div>
                <div class="ptext"><em>4</em><br/><strong>完成</strong></div>
            </div>
        </div>
        <form class="forget-pwd" id="findPassword">
            <dl>
                <dt>账户名：</dt>
                <dd><input id="userName" type="text"/></dd>
                <div class="clears"></div>
            </dl>
            <dl>
                <dt>验证码：</dt>
                <dd>
                    <input type="text" id="codeInput">
                    <div class="validateCode">
                        <input type="button" id="codeVal" onclick="createCode()"/>
                    </div>
                </dd>
                <div class="clears"></div>
            </dl>
            <div class="submit"><input id="submit" type="submit" value="提交"/></div>

        </form><!--forget-pwd/-->

        <script type="text/javascript">

            $().ready(function () {
                $("#submit").click(function () {
                    var userName = $("#userName").val();
                    var inputCode = document.getElementById("codeInput").value.toUpperCase(); //取得输入的验证码并转化为大写
                    if (inputCode.length <= 0) { //若输入的验证码长度为0
                        alert("请输入验证码！"); //则弹出请输入验证码
                        return false;
                    } else if (inputCode != code) { //若输入的验证码与产生的验证码不一致时
                        alert("验证码输入错误！@_@"); //则弹出验证码输入错误
                        createCode();//刷新验证码
                        document.getElementById("input").value = "";//清空文本框
                        return false;
                    } else if (userName == "" || userName.replace(/\s/g, "") == "") {
                        alert("请输入用户名");
                    } else {
                        $.ajax({
                            url: "checkUser.action",
                            type: "POST",
                            data: {
                                "UserName": userName,
                            },
                            async: false,
                            success: function (result) {
                                if (result == "true") {
                                    $.ajax({
                                        url: "getEmailNum.action",
                                        type: "POST",
                                        data: {
                                            "UserName": userName,
                                        },
                                        async: false,
                                        success: function (result) {
                                            if (result == "true") {
                                                window.location.href = "findPasswordPartII.jsp";
                                                window.event.returnValue = false;
                                            }
                                        }
                                    });
                                } else {
                                    alert("用户名不存在");
                                }
                            }
                        });
                    }
                })
            })
        </script>

    </div><!--web-width/-->
</div><!--content/-->

</body>
</html>